//delete//
const Utils = require("../util/utils")
const statusCode = require('../util/status-code')
const getSdkPageList = require("../mock/server/getSdkPageList");
const getSdkList = require("../mock/server/getSdkList");
const getSdkDetail = require("../mock/server/getSdkDetail");

//delete//
class SdkReleaseController {
    /**
     * 创建信息
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async create(ctx) {
        let req = JSON.parse(ctx.request.body);
        const { projectId } = req
        //根据选的点位和点位下的字段，调用生成脚本的模块，生成脚本，然后保存入库
        req.status = 1; //1发布成功，2发布失败
        req.version = 'v1.0.0';
        if (req.releaseName && req.projectId && req.pointIds && req.status && req.version) {
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('创建SDK发布成功', '')
        } else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('创建SDK发布失败，请求参数不能为空！')
        }
    }

    /**
     * 更新
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async update(ctx) {
        let req = JSON.parse(ctx.request.body);
        let id = req.id;
        if (req) {
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('更新信息成功！', '');
        } else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('更新信息失败！')
        }
    }

    /**
     * 删除
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async delete(ctx) {
        let param = JSON.parse(ctx.request.body);
        const { id } = param
        // 删除前，先检查是否还有
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', "")
    }

     /**
     * 获取sdk详情
     * 1、探针代码
     * 2、点位列表
     * @param {*} ctx 
     */
     static async detail(ctx){
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('查询详情成功！', getSdkDetail)
        
    }

    /**
     * page
     * @param 
     * 
     */
    static async getPageList(ctx) {
        let req = ctx.request.body
        const params = JSON.parse(req)
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getSdkPageList)
    }

    /**
     * 列表
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async getList(ctx) {
        let req = ctx.request.body
        const params = JSON.parse(req)
        const { releaseName, projectId, status} = params;
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getSdkList)
    }

    /**
     * 全部
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async getAllList(ctx) {
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getSdkList)
    }

    /**
     * 下载脚本文件
     * @param {}} ctx 
     */
    static async downloadScript(ctx){
        const param = Utils.parseQs(ctx.request.url)
        let id = param.id;
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('这是demo数据，不支持下载', )
       
    }
}
//exports//
module.exports = SdkReleaseController
//exports//